package com.wm.javamall.member.controller;

import com.wm.common.utils.PageUtils;
import com.wm.common.utils.R;
import com.wm.javamall.member.entity.MemberReceiveAddressEntity;
import com.wm.javamall.member.service.MemberReceiveAddressService;
import com.wm.javamall.member.vo.AddressVo;
import com.wm.javamall.ware.vo.FareVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 会员收货地址
 *
 * @author weiming
 * @email sshdg140135@foxmail.com
 * @date 2020-12-20 17:30:33
 */
@RestController
@RequestMapping("member/memberreceiveaddress")
public class MemberReceiveAddressController {
    @Autowired
    private MemberReceiveAddressService memberReceiveAddressService;


    @GetMapping("/fare")
    public R getFare(@RequestParam Long addrId){
        FareVo fare = memberReceiveAddressService.getFare(addrId);
        return R.ok().setData(fare);
    }

    @GetMapping("/{memberId}/address")
    public List<MemberReceiveAddressEntity> getAddress(@PathVariable("memberId") Long memberId){
        return memberReceiveAddressService.getAddress(memberId);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("member:memberreceiveaddress:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberReceiveAddressService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("member:memberreceiveaddress:info")
    public R info(@PathVariable("id") Long id){
		MemberReceiveAddressEntity memberReceiveAddress = memberReceiveAddressService.getById(id);

        return R.ok().put("memberReceiveAddress", memberReceiveAddress);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AddressVo addressVo){
        memberReceiveAddressService.saveAddress(addressVo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("member:memberreceiveaddress:update")
    public R update(@RequestBody MemberReceiveAddressEntity memberReceiveAddress){
		memberReceiveAddressService.updateById(memberReceiveAddress);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody AddressVo addressVo){

		memberReceiveAddressService.removeAddress(addressVo);

        return R.ok();
    }

    /**
     * 设置默认
     */
    @RequestMapping("/default")
    public R setDefault(@RequestBody AddressVo addressVo ){

        memberReceiveAddressService.setDefault(addressVo);

        return R.ok();
    }

}
